import {createRouter, createWebHashHistory, RouteRecordRaw} from "vue-router";
import mainRouterMap from "./constantRouterMap"
import themeRouterMap from "./path2map";
import theme from "../theme";

function path2maps(paths) {
	// console.log(paths);
	let arr = [];
	for (let k in paths) {
		arr.push(paths[k]);
	}
	return arr;
}

// 常规路由表
export const constantRouterMap = themeRouterMap;

//主题路由表
const _theme = theme();
let themeRoutes: RouteRecordRaw[];
switch (_theme) {
	case "_single":
		const paths = await import("@/themes/_single/router/index");
		themeRoutes = path2maps(paths.default);
		break;
	case "notheme":
		themeRoutes = mainRouterMap;
		break;
	case "element":
	default:
		themeRoutes = themeRouterMap;
}
// console.log(_theme, themeRoutes);
// 过滤路由表
export const asyncRoutes = themeRoutes;

export default createRouter({
	history: createWebHashHistory(),
	routes: asyncRoutes
})
